package com.sailing.lianxi.common;

/**
 * 排序枚举--(自定义属性枚举)
 * @author Administrator
 *
 */
//1:定义类型为enum类型
public enum SortEnum {

	ASC("asc","升序"),
	DESC("desc","倒序");
	
	//2：自定义属性，并且生成属性的set和get方法
	private String key;
	private Object value;
	
	//3:增加枚举构造方法
	private SortEnum(String key,Object value) {
		this.key = key;
		this.value = value;
	}
	
	public String getKey() {
		return key;
	}
	public void setKey(String key) {
		this.key = key;
	}
	public Object getValue() {
		return value;
	}
	public void setValue(Object value) {
		this.value = value;
	}
	
	/**
	 * 根据key找value
	 * @param key
	 * @return
	 */
	public static  Object getValueByKey(String key) {
		SortEnum[] enums  = SortEnum.values();
		for (int i = 0; i < enums.length; i++) {
			if(enums[i].getKey().equals(key)) {
				return enums[i].getValue();
			}
		}
		return null;
	}
	
	public static void main(String[] args) {
		System.out.println("key="+SortEnum.ASC.getKey()+",value="+SortEnum.ASC.getValue());
		System.out.println("key="+SortEnum.DESC.getKey()+",value="+SortEnum.DESC.getValue());
	}
	
}
